#!/bin/bash
#destory the vagrant
vagrant destroy  a2ucx -f
vagrant status a2ucx
#up the vagrant then run the case
#sed -i _bak "s/1536/7168/" ../Vagrantfile
retryTime=$1
if [ $? -eq 0 ];then
date +%Y-%m-%d==%H:%M:%S
BeginUpVagrantTime=$(date +%Y-%m-%d==%H:%M:%S)
echo "BeginUpVagrantTime : $BeginUpVagrantTime"
echo "==========vagrant destory success , Now Begin to vagrant up the a2ucx ,$BeginUpVagrantTime =========="
vagrant up a2ucx
  if [ $? -eq 0 ];then
    EndUpVagrantTime=$(date +%Y-%m-%d==%H:%M:%S)
    echo "================BeginUpVagrantTime : $BeginUpVagrantTime &&&&&& EndUpVagrantTime : $EndUpVagrantTime========"

    # Loop until platform is available
    printf 'Waiting PCS-war service to load\n'
    until $(curl --output /dev/null --silent --head --fail http://platform.vagrant.foxitcloud.com:8003); do
        printf '.'
    sleep 1
    done
    printf '\n'
# ssh into the vagrant then excute the case shell
   sshpass -p 'vagrant' ssh -t root@192.168.65.10 sh /vagrant/webapp/tests/jenkins-1box.sh $retryTime

#cat ~/.ssh/id_rsa.pub |ssh root@192.168.65.10 'cat>>.ssh/authorized_keys'
#ssh -t root@192.168.65.10 sh /vagrant/webapp/tests/jenkins-1box.sh $retryTime
  else
    echo "can not remote to the a2ucx , please check";
  fi

else
echo "vagrant destroy fail"
fi

exit $?;

